﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

namespace Nivdal.TBP
{
    public class NewForumConvert
    {
        public string ConvertUrlsToLinks(string msg)
        {
            string regex1 = @"((www\.nivdal|(http|https)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
            string regex2 = @"((www\.|(http|https|)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
            Regex r1 = new Regex(regex1, RegexOptions.IgnoreCase);
            Regex r2 = new Regex(regex2, RegexOptions.IgnoreCase);
            //string TempMsg = r.Replace(msg, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www");
            String TempMsg = null;
            //String ConvMsg;
            TempMsg = r2.Replace(msg, "<a href=\"$1\"  target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www");
            //ConvMsg = r1.Replace(TempMsg, "<a href=\"$1\">$1</a>").Replace("href=\"www", "href=\"http://www");
            return TempMsg;
            //return ConvMsg;
            //return TempMsg.Replace(msg, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www");
        }

    }
}